<%!@SuppressWarnings("unchecked") %>
<%@ page import="com.pension.servlet.calendar.Calendars"%>
<%@ page import="java.util.*" %>

<%@ page import="com.pension.model.dao.MemberDao"%>
<%@ page import="com.pension.model.dao.ReservationDao"%>
<%@ page import="com.pension.model.dao.RoomDao"%>

<%@ page import="com.pension.model.dao.RoomoptionDao"%>
<%@ page import="com.pension.model.dto.Roomoption"%>

<%@ page import="com.pension.model.dto.Member"%>
<%@ page import="com.pension.model.dto.Reservation"%>
<%@ page import="com.pension.model.dto.Room"%>

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<%!
	public String path;
%>

<%
	//System.out.printf("in a calendar jsp..");

	// 여기에 접근 예외처리

	//System.out.printf("ok!\r\n");
	
	// 설정값 로드
	Boolean adminMod = (Boolean)request.getAttribute(Calendars.ADMINMOD);
	
	if ( adminMod == null )
		adminMod = new Boolean(false);
	
	ArrayList<Integer> roomsarray = (ArrayList<Integer>)request.getAttribute(Calendars.ROOMSLIST);
	String remoteid = (String)request.getAttribute(Calendars.REMOTE_ID);
	path = request.getRequestURL().toString();
	String mod = request.getParameter("mod");
	
	// 로그인 섹션 가져오기
	MemberDao memberDao = new MemberDao();
	RoomDao roomDao = new RoomDao();
	RoomoptionDao roomoptionDao = new RoomoptionDao();
	ReservationDao reservationDao = new ReservationDao();
	Member loginuser = (Member)request.getSession().getAttribute("loginuser");
	
	// 모드 구분
	if ( mod != null )
	{
		if ( !mod.isEmpty() )
		{
			if ( mod.equals("admin") )
			{
				adminMod = Calendars.YES;
			}
		}
	}
	
	// 단독 접근일때만 헤더 호출, DIV 인자 호출일 경우 헤더는 포함되지 않도록 구현 요망
	pageContext.include("/WEB-INF/views/include/header.jsp");
	
	// 관리자 모드 권한 체크
	if ( adminMod == Calendars.YES )
	{
		if ( loginuser != null )
		{
			if ( !loginuser.getUserType().equals("admin") )
			{
				//this.destroy();
				//return;
				
				adminMod = Calendars.NO;
			}
			else
			{
				// 관리자 모드 허용
				System.out.println( loginuser.getMemberId() + "가 관리자 모드로 승인되었습니다.");
				adminMod = Calendars.YES;
			}
		}
		else
		{
			adminMod = Calendars.NO;
			//this.destroy();
			//return;
		}
	}
	
%>
<!DOCTYPE html>
<html>
<head>
	<% // 단독/div 체크 요망 { %>
	<meta charset="utf-8" /	>
	<title>예약확인</title>
	<% // } %>
<link rel="Stylesheet" href="../styles/default.css" />
<link rel="Stylesheet" href="../styles/calendar.css" />
<script type="text/javascript" src="../js_lib/prototype.js"></script>
<script type="text/javascript" src="../js_lib/UTools.js"></script>
<script type="text/javascript" src="../js_lib/CalendarJS.js"></script>
<script type="text/javascript" src="../js_lib/Slider.js"></script>
<script src="http://yui.yahooapis.com/3.15.0/build/yui/yui-min.js"></script>

<script>
	var FocusSave = (function()
	{
		FocusSave.MOUSEUP = "mouseup";
		FocusSave.MOUSEDOWN = "mousedown";
		FocusSave.MOUSEMOVE = "mousemove";
		
		// 선택 정보
		this.form_select =
		{
			reser: null,
			room: null,
			s_date: null,
			s_yy: 0,
			s_mm: 0,
			s_dd: 0,
			e_date: null,
			e_yy: 0,
			e_mm: 0,
			e_dd: 0
		};
		
		this.mouse_state =
		{
			isreser : false,
			ismousedown : false,
			ismousemove : false,
			pulse :
			{
				index : null,
				index_date : null,
				reser : null,
				move_index : null,
				move_index_date : null
			}
		};
		
		this.render_date = 
		{
			yy: 0,
			mm: 0
		};
		
		// 빠른 로딩을 위한 예약정보 캐시화, cache_reservations(dateindex, roomindex) = 예약정보
		FocusSave.CACHE = null;
		this.rooms_match = null;
		
		this.getCache = function(carendar_idx, room_idx)
		{
			try
			{
				return FocusSave.CACHE[carendar_idx][room_idx];
			}
			catch(ex)
			{
				return null;
			}
		};
		
		this.loadCache = function()
		{
			var temp_date_min = new Date(this.date_min_string);
			var temp_date_max = new Date(this.date_max_string);
			var size_reser = this.array_reservations.length;
			var siez_rooms = this.array_rooms.length;
			var siez_calendar = Math.round((temp_date_max.getTime() - temp_date_min.getTime()) / 86400000) + 1;
			this.rooms_match = new Array();
			
			FocusSave.CACHE = new Array();
			for ( var c = 0; c < siez_calendar; ++c )
			{
				FocusSave.CACHE[c] = new Array();
			}
			for ( var d = 0; d < siez_rooms; ++d )
			{
				this.rooms_match[this.array_rooms[d].roomNumber] = d;
			}
			
			for ( var i = 0; i < size_reser; i++ )
			{
				var reser = save.array_reservations[i];
				
				for ( var j = 0; j < reser.days; ++j )
				{
					var r_date_check = new Date(reser.startdate);
					r_date_check.setDate( r_date_check.getDate() + j * 1 );
					var r_date_check_index = Math.round((r_date_check.getTime() - temp_date_min.getTime()) / 86400000);
					
					if ( (r_date_check_index < 0) || (r_date_check_index >= siez_calendar) )
						continue;
					
					FocusSave.CACHE[r_date_check_index][this.rooms_match[reser.roomnumber]] = reser;
					
					//console.log("인덱 분해 : " + r_date_check.toDateString() + "  " + temp_date_min.toDateString() + "  차이인덱스 : " + r_date_check_index + "   그것에 룸 넘버: " + reser.roomnumber + "  접근은? : " + rooms_match[reser.roomnumber]);
					//console.log("캐싱 : " + r_date_check_index + " , " + rooms_match[reser.roomnumber] + "  예약번호: " + reser.resernumber);
					
// 					r_date_check.setDate( r_date_check.getDate() + j * 1 );
					
// 					if (r_date_check.getTime() >= temp_date_min.getTime() && r_date_check.getTime() <= temp_date_max.getTime() )
// 					{
						
// 					}
				}
				
// 				var reser = save.array_reservations[c];
// 				var checkDate = new Date(in_block_day_index_date);
// 				var startDate = new Date(reser.startdate);
// 				var endDate = new Date(reser.startdate);
// 				endDate.setDate( endDate.getDate() + (reser.days - 1) * 1);
				
// 				if (checkDate.getTime() >= startDate.getTime() && 
// 						checkDate.getTime() <= endDate.getTime() &&
// 						reser.roomnumber == save.array_rooms[temp_select_room].roomNumber )
// 				{
// 					save.form_select_room = save.array_rooms[temp_select_room];
// 					save.form_select_reservation = reser;
					
// 					in_room = temp_select_room;
// 				}
			}
		};
		
		this.form_option = new Array();
		
		this.form_people = 0;
		this.reservationObject_reserNumber = 0;
		this.focusType = 0;
		
		this.today_yy = 0;
		this.today_mm = 0;
		this.today_dd = 0;
		
		this.date_min_string;
		this.date_max_string;
		
		this.array_rooms;
		this.array_options;
		this.array_reservations;
		
		this.ajax;
		this.resp;
		
		
		FocusSave.prototype.test = function()
		{
		    
		};
	});
	
	function log(str)
	{
		console.log(str);
	}
	
	var tool = new UTools();
	var save = new FocusSave();
	var calendarjs = new CalendarJS();
	
	var initVar = [0,0];
	
	var buffer;
	
	var currYear = 0;
	var currMonth = 0;
	
	var safelimit = 0;
	
	var color_table = ["e0e0f0", "f0f0d0", "d0f0d0", "f0d0d0", "f0f0d0", "d0c0f0", "e0f0c0"];
	
	var s_border = "border:0px #8C8A8D solid; ";
	
	var s_margin_left = "margin:0; left : 6px;";
	var s_margin_center = "margin:0;";
	var s_margin_right = "margin:0; right : 6px;";
	
	var s_margin_left_fix = "margin:0 0 0 6px;";
	var s_margin_center_fix = "margin:0;";
	var s_margin_right_fix = "margin:0 0 6px 0;";
	
	var s_margin_center_ex = "margin:0 4px 0 4px; left : 6px; right : 6px;";
	
	var s_margin_right_in_exisn = "right : 15%;";
	
	var s_radius_left = "border-top-left-radius: 10px; border-bottom-left-radius: 10px; ";
	var s_radius_right = "border-top-right-radius: 10px; border-bottom-right-radius: 10px; ";
	var s_relative_lv4 = "position: relative; z-index: 4; ";
	var s_relative_lv3 = "position: relative; z-index: 3; ";
	var s_relative_lv2 = "position: relative; z-index: 2; ";
	var s_padding = " padding : 1px;";
	var s_width_over = " width : 115%;";
	var s_color_outline = " background-color:#0f0f0f;";
	var s_textoption_left = " text-align: left;";
	var s_default_div = " "; 
	var s_color_bar = "";
	var s_style_outside = "";
	var s_style_inside = "";
	var s_text_inside = "";
	
	
	function selectorBox(x,y,w,h)
	{	
		return [ Math.floor( Math.max(0, x) / w ), Math.floor( Math.max(0, y) / h ) ];
	}
	
	window.onmouseup = function(event)
	{
		if ( save.mouse_state.ismousedown )
		{
			eventCall_block_day(event);
		}
	};
	
	var eventCall_block_day = function(event)
	{
		//log("이벤트 타입: " + event.type);
		
		if ( event.type == FocusSave.MOUSEDOWN )
		{
			save.mouse_state.ismousedown = true;
		}
		else if ( event.type == FocusSave.MOUSEUP )
		{
			save.mouse_state.ismousedown = false;
			save.mouse_state.ismousemove = false;
		}
		else if ( event.type == FocusSave.MOUSEMOVE && save.mouse_state.ismousedown === true )
		{
			save.mouse_state.ismousemove = true;
		}
		else
			return event;
		
		var view_doc = document.getElementById("calendar_table");
		var view_doc_body = document.getElementById("calendar_table_body");
		var view_doc_block_day = document.getElementById("block_day");
		var view_doc_block_day_bar = document.getElementById("block_day_bar");
		var point_target = document.getElementById("calendar_ect");
		
		var view_rect = view_doc.getClientRects()[0];
		var view_body_rect = view_doc_body.getClientRects()[0];
		var block_day_rect = view_doc_block_day.getClientRects()[0];
		var block_day_bar_rect = view_doc_block_day_bar.getClientRects()[0];
		
		// 실제 block_day 그룹 영역
		var block_days_rect = {
			width : view_body_rect.width - 1,
			height : (view_rect.height - ( block_day_rect.top -  view_rect.top )) - 2,
			top : block_day_rect.top - 2,
			left : block_day_rect.left - 2,
			single_day :
			{
				width : block_day_rect.width + 2 - 1,
				height : block_day_rect.height + 2 - 1
			},
			single_room :
			{
				width : block_day_bar_rect.width,
				height : (block_day_rect.height - (block_day_bar_rect.top - block_day_rect.top)) / save.array_rooms.length,
				surplus : (block_day_bar_rect.top - block_day_rect.top) + 1
			}
		};
		
		var mouse_x = (event.clientX || event.pageX || event.x);
		var mouse_y = (event.clientY || event.pageY || event.y);
		
		var offset_x = (mouse_x - block_days_rect.left);
		var offset_y = (mouse_y - block_days_rect.top);
		
// 		log("w : " + block_days_rect.width);
// 		log("h : " + block_days_rect.height);
// 		log("l : " + block_days_rect.left);
// 		log("t : " + block_days_rect.top);
// 		log("x : " + offset_x);
// 		log("y : " + offset_y);
		
		// 마우스 포인트가 해당 block_day 그룹들 영역이 아니라면 리턴
		if (
				((offset_x < 0)
				||
				(offset_y < 0)
				||
				(offset_x >= block_days_rect.width)
				||
				(offset_y >= block_days_rect.height))
				&& ( save.mouse_state.ismousemove != true )
			)
		{
			//log("힝 : " + offset_x + " vs " + (block_day_rect.left - view_rect.left) + "   " + offset_y + " vs " + ( block_day_rect.top - view_rect.top ) );
			
			save.mouse_state.pulse.index = null;
			save.mouse_state.pulse.index_date = null;
			save.mouse_state.pulse.reser = null;
			save.mouse_state.pulse.move_index = null;
			save.mouse_state.pulse.move_index_date = null;
			save.mouse_state.isreser = false;
			save.mouse_state.ismousemove = false;
			console.log("그외 영역에서 누르거나 땜!");
			
			return event;
		}
		
		// 선택한 block_day의 인덱스 좌표
		var in_block_day_index_pos = selectorBox(offset_x, offset_y, block_days_rect.single_day.width, block_days_rect.single_day.height);
		var in_block_day_index = (in_block_day_index_pos[0] + ( in_block_day_index_pos[1] * 7 ));
		
		// 선택한 block_day가 가르키는 날짜
		var in_block_day_index_date = new Date(save.date_min_string);
		in_block_day_index_date.setDate( in_block_day_index_date.getDate() + in_block_day_index * 1);
		
		// 선택한 block_day중 룸 인덱스
		var offset_day_x = offset_x%block_days_rect.single_day.width;
		var offset_day_y = offset_y%block_days_rect.single_day.height;
		
		var in_room = -1;
		var chacker_reser = null;
		save.mouse_state.isreser = false;
		
		if ( offset_day_y > block_days_rect.single_room.surplus )
		{
			var temp_select_room = Math.min(Math.floor((offset_day_y - block_days_rect.single_room.surplus) / block_days_rect.single_room.height), save.array_rooms.length - 1);
			
			// 실제로 예약정보가 있는 방인지 체크하고, 있다면 예약 정보를 얻어옴
			chacker_reser = save.getCache(in_block_day_index, temp_select_room);
			
			if ( chacker_reser )
			{
				//console.log("찾았음!! " + "예약번호=" + chacker_reser.resernumber);
				
				save.form_select.room = save.array_rooms[temp_select_room];
				save.form_select.reser = chacker_reser;
				in_room = temp_select_room;
				
				save.mouse_state.isreser = true;
				
		 		var dates = (chacker_reser.startdate + "").split("-");
				
			}			
		}
		
		// 본격적인 UI 데이터 분석 시작----------
		
// 		A 빈 공간을 누르고 같은 위치(같은 인덱스)에서 땔 경우
// 		B 빈 공간을 누르고 후 위치 빈공간에서 땔 경우
// 		C 빈 공간을 누르고 전 위치 빈공간에서 땔 경우
// 		D 빈 공간을 누르고 같은 위치 예약정보에서 땔 경우
// 		E 빈 공간을 누르고 후 위치 예약정보에서 땔 경우
//		F 빈 공간을 누르고 전 위치 예약정보에서 땔 경우
// 		G 예약 정보를 누르고 같은 예약정보에서 땔 경우
//		H 예약 정보를 누르고 같은 위치(같은 인덱스) 다른 예약정보에서 땔 경우
// 		I 예약 정보에서 누르고 후 위치 예약 정보에서 땔 경우
// 		J 예약 정보에서 누르고 전 위치 정보에서 땔 경우
// 		K 예약 정보를 누르고 빈 공간에서 땔 경우
// 		L 예약 정보를 누르고 후 위치 빈공간에서 땔 경우
// 		M 예약 정보를 누르고 전 위치 빈공간에서 땔 경우
//		N 그외 뭐든 누르고 엉뚱한 위치에서 땔 경우

	 	// 유효한것 : A,B,D(),E(), G..  HIJKLM은 무효화

		if ( save.mouse_state.ismousedown )
		{
			if ( save.mouse_state.ismousemove )
			{
				// 빈 정보를 누른 상태로 마우스 이동 중 위치 정보가 바뀌었다면
				if ( save.mouse_state.pulse.move_index != in_block_day_index )
				{
					save.mouse_state.pulse.move_index = in_block_day_index;
					save.mouse_state.pulse.move_index_date = in_block_day_index_date;
					
					//console.log("마우스 이동 타겟(위치) 바뀜");
					//calendar_drow(null, null, null, true);

					// 그래프 타겟팅 시스템 추가시 이러한 구현으로 시각적인 그래프를 제공하는 식으로..
			        //point_target.innerHTML = "";
			        //point_target.innerHTML += "<div id='point' style='top: "++"px; left: "++"px;'></<div>";
				}
			}
			else
			{
				save.mouse_state.pulse.index = save.mouse_state.pulse.move_index = in_block_day_index;
				save.mouse_state.pulse.index_date = save.mouse_state.pulse.move_index_date = in_block_day_index_date;
				save.mouse_state.pulse.reser = null;
				
				if ( save.mouse_state.isreser )
				{
					// 예약 정보를 누르고
					save.mouse_state.pulse.reser = chacker_reser;
					//console.log("예약 정보를 누르고..");
				}
				else
				{
					// 빈 공간을 누르고
					save.mouse_state.pulse.reser = null;
					//console.log("빈 공간을 누르고..");
				}
			}
		}
		else
		{
			if ( save.mouse_state.isreser )
			{
				if ( save.mouse_state.pulse.reser == chacker_reser )
				{
					// 같은 예약 정보에서 땔 경우
					//console.log("같은 예약정보에서 땜!");
					
					controlSetup_reser(chacker_reser);
				}
				else if ( save.mouse_state.pulse.index == in_block_day_index && save.mouse_state.pulse.reser == null )
				{
					//빈 공간을 누르고 같은 위치 예약정보에서 땔 경우
					//console.log("빈공간을 눌렀지만 동일한 위치에 있는 예약정보에서 땜!");
					
					// ㅁ 여기에 (1일) 날짜 예약 콜
					controlSetup_join(save.mouse_state.pulse.index, in_block_day_index, save.mouse_state.pulse.index_date, in_block_day_index_date);
				}
				else if ( save.mouse_state.pulse.reser == null )
				{
					//빈 공간을 누르고 다른 위치 예약 정보에서 땔 경우
					//console.log("빈공간을 눌렀지만 다른 위치에 있는 예약정보에서 땜!");
					
					// ㅁ 여기에 (n일) 날짜 예약 콜
					controlSetup_join(save.mouse_state.pulse.index, in_block_day_index, save.mouse_state.pulse.index_date, in_block_day_index_date);
				}
				else
				{
					//그외 예약정보에서 땔 경우
					//console.log("엉뚱한 예약정보에서 땜!");
				}
			}
			else
			{
				if ( save.mouse_state.pulse.index == in_block_day_index )
				{
					// 같은 위치(인덱스)에서 땔 경우
					//console.log("같은 위치(인덱스)에서 땜!");
					
					// ㅁ 여기에 (1일) 날짜예약 콜
					controlSetup_join(save.mouse_state.pulse.index, in_block_day_index, save.mouse_state.pulse.index_date, in_block_day_index_date);
				}
				else
				{
					// 다른 위치에서 땔 경우
					//console.log("다른 위치(인덱스)에서 땜!");
					
					// ㅁ 여기에 (n일) 날짜 예약 콜
					controlSetup_join(save.mouse_state.pulse.index, in_block_day_index, save.mouse_state.pulse.index_date, in_block_day_index_date);
				}
			}
			
			save.mouse_state.pulse.index = null;
			save.mouse_state.pulse.index_date = null;
			save.mouse_state.pulse.reser = null;
			save.mouse_state.isreser = false;
			save.mouse_state.ismousemove = false;
			save.mouse_state.pulse.move_index = null;
			save.mouse_state.pulse.move_index_date = null;
		}
		

		// . 빈공간에서 마우스를 누른 black_day에서 마우스를 누른 상태로 이동(move)하여 다른 black_day에 도달했을 경우
		//  ㄴ 이동 안전값(r : 반지름)에 벗어나 확실히 의도된 경우, 가상의 focus bar 보여주기
		//    ㄴ 구현은 어떻게? 현재 calendar_drow에 focusMod로 의존할 것인가, 절대좌표로 "드로잉"해줄 것인가?
		//       ㄴ 그 경우 이미 있는 예약정보와 충돌은 어떻게?
		//       ㄴ 정확한 한도와 week 바뀜은 어떻게?
		// .
		
		
		// 구현 이슈!
		// control의 반영과 예약정보 등록, 수정이 가능토록.
		// 그런데 타팀원의 예약정보 상세정보 페이징은 어떻게 되지? ☆체크 요망!
		
	};
	
	/*
	var eventCall_block_day = function(event, target, dateStr, flug)
	{
		var control_doc_input_yy = document.getElementById("input_yy");
		var control_doc_input_mm = document.getElementById("input_mm");
		var control_doc_input_dd = document.getElementById("input_dd");
		
		if ( control_doc_input_yy && control_doc_input_mm && control_doc_input_dd )
		{
			var dates = dateStr.split("-");
			
			control_doc_input_yy.value = save.form_select_yy = dates[0];
			control_doc_input_mm.value = save.form_select_mm = ((dates[1][0]=="0"&&dates[1].length>1)?dates[1].substring(1,dates[1].length):dates[1]);
			control_doc_input_dd.value = save.form_select_dd = ((dates[2][0]=="0"&&dates[2].length>1)?dates[2].substring(1,dates[2].length):dates[2]);
			
			// 마우스 Y 오프셋을 해석하여, 어떤 room을 클릭했는지 알아낸다.
			var relative_mouseY = event.layerY || event.offsetY;
			
			if ( !relative_mouseY )
			{
				if(event.pageX)
			    {
					relative_mouseY = event.pageY - target.offsetTop;
			    }
			    else if (event.clientX)
			    {
			    	relative_mouseY = event.clientY + document.body.scrollTop - document.body.clientTop - target.offsetTop;
			    }
				
				if(document.body.parentElement && document.body.parentElement.clientLeft)
				{
			        var b = document.body.parentElement;
			        relative_mouseY += b.scrollTop - b.clientTop;
			    }
			}
			
			//console.log(" 마우스 Y 오프셋 : " + relative_mouseY);
			
			var view_block_day = document.getElementById("block_day");
			var view_block_day_bar = document.getElementById("block_day_bar");
			
			if ( view_block_day && view_block_day_bar )
			{
				var view_block_day_height = view_block_day.getHeight();
				var view_block_day_bar_height = view_block_day_bar.getHeight();
				
				var coordinate = (view_block_day_height - ((view_block_day_bar_height + 4) * save.array_rooms.length));
				
				if (coordinate < relative_mouseY)
				{
					var target_roomdata = save.array_rooms[parseInt((relative_mouseY-coordinate)/(view_block_day_bar_height + 4))];
					
					if ( target_roomdata )
					{
						// 이렇게 얻은 날짜, 방번호를 바탕으로 예약 정보가 있는지 확인(저장 객체 사용)
						var arrayLen = save.array_reservations.length;
						
						for ( var c = 0; c < arrayLen; c++ )
						{
							var reser = save.array_reservations[c];
							var checkDate = new Date(dateStr);
							var startDate = new Date(reser.startdate);
							var endDate = new Date(reser.startdate);
							endDate.addDate(reser.days - 1);
							
							if (checkDate.getTime() >= startDate.getTime() && 
									checkDate.getTime() <= endDate.getTime() &&
									reser.roomnumber == target_roomdata.roomNumber )
							{
								console.log("찾았음!! " + "예약번호=" + reser.resernumber + "  예약날짜=" + startDate.getDate() + " 지금일자=" + checkDate.getDate() +  " vs  끝나는날짜=" + endDate.getDate() + "           days=" + reser.days );
								
								save.form_select_room = target_roomdata;
								save.form_select_reservation = reser;
								
								break;
							}
						}
					}
				}
					
			}	
		}
	};
	*/
</script>
<script>
	
	function controlSetup_reser(reser)
	{
		if ( !reser )
			return;
		
		var control_doc = document.getElementById("form_fixed");
		
		var control_doc_form_head_info = document.getElementById("form_head_info");
		var control_doc_form_head_join = document.getElementById("form_head_join");
		var control_doc_form_head_line = document.getElementById("form_head_line");
		
		var control_doc_form_date1 = document.getElementById("form_date1");
		var control_doc_input_s_yy = document.getElementById("input_s_yy");
		var control_doc_input_s_mm = document.getElementById("input_s_mm");
		var control_doc_input_s_dd = document.getElementById("input_s_dd");
		var control_doc_form_date2 = document.getElementById("form_date2");
		var control_doc_input_e_yy = document.getElementById("input_e_yy");
		var control_doc_input_e_mm = document.getElementById("input_e_mm");
		var control_doc_input_e_dd = document.getElementById("input_e_dd");
		var control_doc_form_slide_days = document.getElementById("form_slide_days");
		var control_doc_form_info1 =document.getElementById("form_info1");
		var control_doc_form_info2 =document.getElementById("form_info2");
		var control_doc_input_room = document.getElementById("input_room");
		var control_doc_input_room_number = document.getElementById("input_room_number");
		var control_doc_input_people = document.getElementById("input_people");
		var control_doc_input_regdate = document.getElementById("input_regdate");
		var control_doc_label_pricetotal = document.getElementById("label_pricetotal");
		var control_doc_input_pricetotal = document.getElementById("input_pricetotal");
		var control_doc_form_options = document.getElementById("form_options");
		
		var control_doc_form_join1 = document.getElementById("form_join1");
		var control_doc_form_join2 = document.getElementById("form_join2");
		var control_doc_form_join3 = document.getElementById("form_join3");
		
		var control_doc_form_room_list = document.getElementById("form_room_list");
		var control_doc_form_option_list = document.getElementById("form_option_list");
		control_doc_form_room_list.style.display = "none";
		control_doc_form_option_list.style.display = "none";
		
		control_doc.style.display = "block";
		control_doc_form_head_info.style.display = "block";
		control_doc_form_head_join.style.display = "none";
		control_doc_form_head_line.style.display = "block";
		
		control_doc_form_date1.style.display = "inline";
		control_doc_input_s_yy.style.display = "inline";
		control_doc_input_s_mm.style.display = "inline";
		control_doc_input_s_dd.style.display = "inline";
		control_doc_form_date2.style.display = "inline";
		control_doc_input_e_yy.style.display = "inline";
		control_doc_input_e_mm.style.display = "inline";
		control_doc_input_e_dd.style.display = "inline";
		control_doc_form_head_line.innerHTML = "";
		control_doc_form_slide_days.style.display = "none";
		//control_doc_form_slide_days.style.display = "inline";
		control_doc_form_info1.style.display = "inline";
		control_doc_form_info2.style.display = "inline";
		control_doc_input_room.style.display = "inline";
		control_doc_input_room_number.style.display = "inline";
		control_doc_input_people.style.display = "inline";
		control_doc_input_regdate.style.display = "inline";
		control_doc_label_pricetotal.style.display = "inline";
		control_doc_input_pricetotal.style.display = "inline";
		control_doc_form_options.style.display = "block";
		
		control_doc_form_join1.style.display = "none";
		control_doc_form_join2.style.display = "none";
		control_doc_form_join3.style.display = "none";
		
		
		
		var dates1 = reser.startdate.split("-");
		
		var dDate = new Date(reser.startdate);
		dDate.setDate( dDate.getDate() + (reser.days - 1) *1);
		
		control_doc_input_s_yy.value = dates1[0];
		control_doc_input_s_mm.value = ((dates1[1][0]=="0"&&dates1[1].length>1)?dates1[1].substring(1,dates1[1].length):dates1[1]);
		control_doc_input_s_dd.value = ((dates1[2][0]=="0"&&dates1[2].length>1)?dates1[2].substring(1,dates1[2].length):dates1[2]);
		
		control_doc_input_e_yy.value = dDate.getFullYear();
		control_doc_input_e_mm.value = dDate.getMonth() + 1;
		control_doc_input_e_dd.value = dDate.getDate();
		
		control_doc_form_head_line.innerHTML =  "<label>no." + reser.resernumber + " &nbsp id : " + reser.memberid + "</label>";
		
//			var bar = new Slider({
//				container: 'form_slide_days',
//		        value: 0.7,
//		        onChange: function(value){
//		            console.log(value);
//		        }
//		    });

		var room = save.array_rooms[save.rooms_match[reser.roomnumber]];

		control_doc_input_room.value = room.roomName;
		control_doc_input_room_number.value = reser.roomnumber;
		control_doc_input_people.value = reser.usepeople;
		control_doc_input_regdate.value = new Date(reser.regdate).toUTCString();
		control_doc_input_pricetotal.value = reser.pricetotal + " $ 　";

		control_doc_form_options.innerHTML = "<br / > NULL <br / >";
		
		var option_str = "";
		
		if ( reser.options )
		{
			for (var c = 0; c < reser.options.length; ++c )
			{
				if ( reser.options[c] )
				{
					//log("옵션 발견 : " + reser.options[c].optionname);
					option_str += "<label><input type='checkbox' id='input_option' value='1' checked='checked' disabled='disabled'>&nbsp "+reser.options[c].optionname+"</label><br /><hr color='#9f9eaa' width='80%'>";
				}
			}
		}
		
		if ( option_str != "" )
		{
			control_doc_form_options.innerHTML = option_str;
		}
	}
	

	function controlSetup_join(idxMin, idxMax, idxMin_date, idxMax_date)
	{
		log("들어옴 " + idxMin+ idxMax+ idxMin_date+ idxMax_date);
		
		if ( idxMin > idxMax || idxMin < 0 )
			return;
		
		//log("idxMin=" + idxMin + "  idxMax=" + idxMax);
		
		var control_doc = document.getElementById("form_fixed");
		
		var control_doc_form_head_info = document.getElementById("form_head_info");
		var control_doc_form_head_join = document.getElementById("form_head_join");
		var control_doc_form_head_line = document.getElementById("form_head_line");
		
		var control_doc_form_date1 = document.getElementById("form_date1");
		var control_doc_input_s_yy = document.getElementById("input_s_yy");
		var control_doc_input_s_mm = document.getElementById("input_s_mm");
		var control_doc_input_s_dd = document.getElementById("input_s_dd");
		var control_doc_form_date2 = document.getElementById("form_date2");
		var control_doc_input_e_yy = document.getElementById("input_e_yy");
		var control_doc_input_e_mm = document.getElementById("input_e_mm");
		var control_doc_input_e_dd = document.getElementById("input_e_dd");
		var control_doc_form_slide_days = document.getElementById("form_slide_days");
		var control_doc_form_info1 =document.getElementById("form_info1");
		var control_doc_form_info2 =document.getElementById("form_info2");
		var control_doc_input_room = document.getElementById("input_room");
		var control_doc_input_room_number = document.getElementById("input_room_number");
		var control_doc_input_people = document.getElementById("input_people");
		var control_doc_input_regdate = document.getElementById("input_regdate");
		var control_doc_label_pricetotal = document.getElementById("label_pricetotal");
		var control_doc_input_pricetotal = document.getElementById("input_pricetotal");
		var control_doc_form_options = document.getElementById("form_options");
		
		var control_doc_form_room_list = document.getElementById("form_room_list");
		var control_doc_form_option_list = document.getElementById("form_option_list");
		control_doc_form_room_list.style.display = "block";
		control_doc_form_option_list.style.display = "block";
		
		var control_doc_form_join1 = document.getElementById("form_join1");
		var control_doc_form_join2 = document.getElementById("form_join2");
		var control_doc_form_join3 = document.getElementById("form_join3");
		
		control_doc.style.display = "block";
		control_doc_form_head_info.style.display = "none";
		control_doc_form_head_join.style.display = "block";
		control_doc_form_head_line.style.display = "block";
		
		control_doc_form_date1.style.display = "inline";
		control_doc_input_s_yy.style.display = "inline";
		control_doc_input_s_mm.style.display = "inline";
		control_doc_input_s_dd.style.display = "inline";
		control_doc_form_date2.style.display = "inline";
		control_doc_input_e_yy.style.display = "inline";
		control_doc_input_e_mm.style.display = "inline";
		control_doc_input_e_dd.style.display = "inline";
		control_doc_form_head_line.innerHTML = "";
		
		control_doc_form_slide_days.style.display = "inline";
		
		control_doc_form_info1.style.display = "none";
		control_doc_form_info2.style.display = "none";
		control_doc_input_room.style.display = "none";
		control_doc_input_room_number.style.display = "none";
		control_doc_input_people.style.display = "none";
		control_doc_input_regdate.style.display = "none";
		control_doc_label_pricetotal.style.display = "none";
		control_doc_input_pricetotal.style.display = "none";
		control_doc_form_options.style.display = "none";
		control_doc_form_join1.style.display = "inline";
		control_doc_form_join2.style.display = "inline";
		control_doc_form_join3.style.display = "inline";
		
		control_doc_input_s_yy.value = idxMin_date.getFullYear();
		control_doc_input_s_mm.value = idxMin_date.getMonth() + 1;
		control_doc_input_s_dd.value = idxMin_date.getDate();
		control_doc_input_e_yy.value = idxMax_date.getFullYear();
		control_doc_input_e_mm.value = idxMax_date.getMonth() + 1;
		control_doc_input_e_dd.value = idxMax_date.getDate();
		
		var days = ((idxMax*1) - (idxMin*1)) + 1;
		
		// 막코딩 ㅠㅠㅠㅠㅠㅠㅠㅠ
		this.save_date1 = control_doc_input_s_yy.value + "-" + fillZero((idxMin_date.getMonth() + 1 * 1), 2) + "-" + fillZero(control_doc_input_s_dd.value, 2);
		this.save_date2 = control_doc_input_e_yy.value + "-" + fillZero((idxMax_date.getMonth() + 1 * 1), 2) + "-" + fillZero(control_doc_input_e_dd.value, 2);
		this.save_idx1 = idxMin;
		this.save_idx2 = idxMax;
		this.save_day = days;
		this.save_time = idxMin_date.getTime();
	}
	
	this.save_date1 = "";
	this.save_date2 = "";
	this.save_idx1 = 0;
	this.save_idx2 = 0;
	this.save_day = 0;
	this.save_time = 0;
	
	function lowSubmit()
	{
		//log("버튼 누름");
		
		var control_doc = document.getElementById("form_fixed");
		
		var control_doc_form_head_info = document.getElementById("form_head_info");
		var control_doc_form_head_join = document.getElementById("form_head_join");
		var control_doc_form_head_line = document.getElementById("form_head_line");
		
		var control_doc_form_date1 = document.getElementById("form_date1");
		var control_doc_input_s_yy = document.getElementById("input_s_yy");
		var control_doc_input_s_mm = document.getElementById("input_s_mm");
		var control_doc_input_s_dd = document.getElementById("input_s_dd");
		var control_doc_form_date2 = document.getElementById("form_date2");
		var control_doc_input_e_yy = document.getElementById("input_e_yy");
		var control_doc_input_e_mm = document.getElementById("input_e_mm");
		var control_doc_input_e_dd = document.getElementById("input_e_dd");
		var control_doc_form_slide_days = document.getElementById("form_slide_days");
		var control_doc_form_info1 =document.getElementById("form_info1");
		var control_doc_form_info2 =document.getElementById("form_info2");
		var control_doc_input_room = document.getElementById("input_room");
		var control_doc_input_room_number = document.getElementById("input_room_number");
		var control_doc_input_people = document.getElementById("input_people");
		var control_doc_input_regdate = document.getElementById("input_regdate");
		var control_doc_label_pricetotal = document.getElementById("label_pricetotal");
		var control_doc_input_pricetotal = document.getElementById("input_pricetotal");
		var control_doc_form_options = document.getElementById("form_options");
		
		var control_doc_form_room_list = document.getElementById("form_room_list");
		var control_doc_form_option_list = document.getElementById("form_option_list");

		var control_doc_form_join1 = document.getElementById("form_join1");
		var control_doc_form_join2 = document.getElementById("form_join2");
		var control_doc_form_join3 = document.getElementById("form_join3");
		
		
		var t = new Array();
		t.push(document.getElementById("input_room_selecter"));
		t.push(document.getElementById("input_option_1"));
		t.push(document.getElementById("input_option_2"));
		t.push(document.getElementById("input_option_3"));
		t.push();
		t.push();
		t.push();
		
		if ( t[0].getValue() == 101 )
		{
			// 101호
		}
		else if ( t[0].getValue() == 102 )
		{
			// 102호
			
		}
		else if ( t[0].getValue() == 201 )
		{
			// 201호
			
		}
		else if ( t[0].getValue() == 202 )
		{
			// 202호
			//log("202호 선택");
		}
		
		var op1 = 0;
		var op2 = 0;
		var op3 = 0;
		
		if ( t[1].getValue() )
		{
			//log("옵션 1 선택");
			op1= 1;
		}
		
		if ( t[2].getValue() )
		{
			//log("옵션 2 선택");
			op2= 1;
			
		}
		
		if ( t[3].getValue() )
		{
			//log("옵션 3 선택");
			op3= 1;
		}
		
		var chk = "/pension/calendar/calendars.action?task=join&room=" + t[0].getValue() + "&op1=" + op1+ "&op2=" + op2+ "&op3=" + op3 + "&start=" + this.save_date1 + "&end=" + this.save_date2 + "&idx1=" + this.save_idx1 + "&idx2=" + this.save_idx2 + "&days=" + this.save_day + "&start_time=" + this.save_time;
		var url2 = "<%= Calendars.CALENDARS_ACTION %>" + "?task=merber_test";
		
		var ajax2 = new Ajax.Request(url2,
		{ 
			method: 'post', 
			parameters: {member_test:1},
			failure: function(error)
			{
				alert("로그인한 사용자만이 예약이 가능합니다..\r\n 회원 가입 페이지를 이용하여 주십시오.");
               	return;
            },
			onSuccess: function(obj)
			{
				if ( obj.responseText.length < 100 )
				{
					alert("로그인한 사용자만이 예약이 가능합니다..\r\n 회원 가입 페이지를 이용하여 주십시오.");
					return;
				}
				else
				{
					alert("예약 처리 완료!");
					location.replace(chk);
				}
			}
		});
		
		
		calendar_drow();
		
		control_doc_form_room_list.style.display = "none";
		control_doc_form_option_list.style.display = "none";
		
		control_doc.style.display = "none";
		control_doc_form_head_info.style.display = "none";
		control_doc_form_head_join.style.display = "none";
		control_doc_form_head_line.style.display = "none";
		
		control_doc_form_date1.style.display = "none";
		control_doc_input_s_yy.style.display = "none";
		control_doc_input_s_mm.style.display = "none";
		control_doc_input_s_dd.style.display = "none";
		control_doc_form_date2.style.display = "none";
		control_doc_input_e_yy.style.display = "none";
		control_doc_input_e_mm.style.display = "none";
		control_doc_input_e_dd.style.display = "none";
		control_doc_form_head_line.innerHTML = "";
		
		control_doc_form_slide_days.style.display = "none";
		
		control_doc_form_info1.style.display = "none";
		control_doc_form_info2.style.display = "none";
		control_doc_input_room.style.display = "none";
		control_doc_input_room_number.style.display = "none";
		control_doc_input_people.style.display = "none";
		control_doc_input_regdate.style.display = "none";
		control_doc_label_pricetotal.style.display = "none";
		control_doc_input_pricetotal.style.display = "none";
		control_doc_form_options.style.display = "none";
		control_doc_form_join1.style.display = "none";
		control_doc_form_join2.style.display = "none";
		control_doc_form_join3.style.display = "none";
		
// 							<div id='form_room_list'>
// 						   	<select id="input_room_selecter"  name="input_room_selecter">
<%-- 							      <option value="1" selected="selected"><%= roomDao.getRoomByRoomNumber(101).getRoomName() %></option> --%>
<%-- 							      <option value="2"><%= roomDao.getRoomByRoomNumber(102).getRoomName() %></option> --%>
<%-- 							      <option value="3"><%= roomDao.getRoomByRoomNumber(201).getRoomName() %></option> --%>
<%-- 							      <option value="3"><%= roomDao.getRoomByRoomNumber(202).getRoomName() %></option> --%>
// 							</select>
// 						   </div>
						   
// 						   <div id='form_option_list'>
// 						   	<label id ="label_option"> - Option - </label>
<%-- 						    <input type='checkbox' name="input_option_1" id='input_option' value='1'><%= roomoptionDao.getRoomsoptionByNumber(1).getOptionname() %><br /><hr color='#9f9eaa' width='80%'> --%>
<%-- 						    <input type='checkbox' name="input_option_2" id='input_option' value='2'><%= roomoptionDao.getRoomsoptionByNumber(2).getOptionname() %><br /><hr color='#9f9eaa' width='80%'> --%>
<%-- 						    <input type='checkbox' name="input_option_3" id='input_option' value='3'><%= roomoptionDao.getRoomsoptionByNumber(3).getOptionname() %><br /><hr color='#9f9eaa' width='80%'> --%>
// 						   </div>
						   
// 						   <div id='form_join1'>
// 						   </div>
// 						   <div id='form_join2'>
// 						   </div>
// 						   <div id='form_join3'>
// 						     <input type="text" id="input_people" value="test">
// 						     <label>People &nbsp</label>
						     
// 						     <br />
// 						     <label>Room Name : &nbsp</label>
// 						     <input type="text" id="input_room"value="se ">
						     
// 						     <label>&nbsp no.</label>
// 						     <input type="text" id="input_room_number"value="se ">
						 	  
// 						 	    <br />
// 						   	<a href="javascript:;" class="b_join" onclick="lowSubmit();">예약하기!</a>
// 						   </div>
	};
	
	window.onload = function()
	{
		console.log("[sys] in window.onload");
		
		Date.prototype.addDate = function (i)
		{
		   var currentDate;
		   currentDate = this.getDate() + i*1;
		   this.setDate(currentDate);
		   
		   return this;
		};
		
		initVar[0] = 1;
		
		onLoad();
	};
	
	YUI().use('node', 'event', function (Y)
	{
		initVar[1] = 1;
		
		onLoad();
	});
	
	function onLoad()
	{
		for (var i = 0; i < initVar.size(); ++i )
		{
			if ( initVar[i] == 0 )
			{
				return;
			}
		}
		
		// 모든 로드 완료 후 실행될 코드
		calendar_drow();
	}
	
	var calendar_drow = function(yy, mm, resp, focusModeFlug)
	{
		console.log("[sys] in calendar_drow : " + yy + " " + mm + " " + resp);
		
		if ( mm == 12 )
		{
			++yy;
			mm = 0;
		}
		else if ( mm == -1 )
		{
			--yy;
			mm = 11;
		}
		
		calendarjs.set(new Date());
		
		save.today_yy = calendarjs.getYear();
		save.today_mm = calendarjs.getMonth();
		save.today_dd = calendarjs.getDayOfMonth();
		
		// 인자가 없을 경우 저장된 날짜/현재 날짜를 기준으로 함
		if ( ((!yy) && (!mm)) )
		{
			if ( focusModeFlug && !(resp) )
			{
				currYear = yy = save.render_date.yy;
				currMonth = mm = save.render_date.mm;
			}
			else
			{
				save.render_date.yy = currYear = yy = calendarjs.getYear();
				save.render_date.mm = currMonth = mm = calendarjs.getMonth();
			}
		}
		else
		{
			calendarjs.setYear(currYear = save.render_date.yy = yy);
			calendarjs.setMonth(currMonth = save.render_date.mm = mm);
		}
		
		//console.log("[sys] currYear=" + currYear + " calendarjs.getYear()=" + calendarjs.getYear() + " currMonth=" + currMonth + " calendarjs.getMonth()=" + calendarjs.getMonth() + " calendarjs.getDayOfMonth()=" + calendarjs.getDayOfMonth() );
		
		if ( ((!save.ajax) && (!resp)) && (!focusModeFlug) )
		{
			calendarjs.setDayOfMonth(1);
			calendarjs.setDayOfWeek(0);
			
			save.date_min_string = calendarjs.getDate();
			
			var month_list = [31, ((calendarjs.getYear() % 4 == 0 && calendarjs.getYear() % 100 != 0) || calendarjs.getYear() % 400)?29:28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
			
			calendarjs.addDay(10);
			calendarjs.setDayOfMonth(month_list[calendarjs.getMonth()]);
			calendarjs.setDayOfWeek(6);
			
			save.date_max_string = calendarjs.getDate();
			
			var url = "<%= Calendars.CALENDARS_ACTION %>" + "?task=<%= Calendars.TASK_RESERVATION_SYSTEM %>";

			console.log("[sys] connections... = " + url);
			
			save.ajax = new Ajax.Request(url,
			{ 
				method: 'post', 
				parameters: {year:save.render_date.yy, month:save.render_date.mm, date_min:save.date_min_string, date_max:save.date_max_string},
				failure: function(error)
				{
					document.write(document.body.innerHTML + "<br /> <h2 style='text-align : center;'> ERROR! failure!! <h2> <br />");
                	console.log('[sys] Ajax failure T_T.. : ' + obj.responseText);                    	
                	document.getElementById('calendar_view').innerHTML = "<h3 style='text-align : center;'> 서버 연결에 실패하였습니다. 관리자에게 문의하십시오. </h3>";
            		
                	return;
                },
				onSuccess: function(obj)
				{
					console.log("[sys] in callback function!");
					
                    if ( obj.responseText.length < 100 )
                    {
                    	document.write(document.body.innerHTML + "<br /> <h2 style='text-align : center;'> ERROR! DB Connect failed!! <h2> <br />");
                    	console.log('[sys] Ajax Connect no Massage T_T.. : ' + obj.responseText);                    	
                    	document.getElementById('calendar_view').innerHTML = "<h3 style='text-align : center;'> 서버 연결에 실패하였습니다. 관리자에게 문의하십시오. </h3>";
                		
                    	return;
                    }
					
                    save.resp = obj;
                    
					calendar_drow(yy, mm, obj, 0);
				}
			});
			
			return;
		}
		else if ( focusModeFlug == 0 )
		{
			console.log("[sys] connections ok. continue.. date : " + currYear + " " + currMonth);
			//console.log("[sys] resp data : " + resp.responseText);	
			save.ajax = null;
			
			// DB에서 받아온 데이터를 파싱 및 저장
			var fixedResponse = resp.responseText; // .replace(/\\'/g, "'");
			var jsonObj = JSON.parse(fixedResponse);
			
			save.array_rooms = JSON.parse(jsonObj.rooms);
			save.array_options = JSON.parse(jsonObj.options);
			save.array_reservations = JSON.parse(jsonObj.reservations);
			
			save.loadCache();
			
			console.log("[sys] AJAX DB 리턴 후, currYear=" + currYear + " calendarjs.getYear()=" + calendarjs.getYear() +
					" currMo0nth=" + currMonth + " calendarjs.getMonth()=" + calendarjs.getMonth() + " calendarjs.getDayOfMonth()=" + calendarjs.getDayOfMonth() );
		}
		
		// 만일 포커스 모드가 1이라면 DB 커넥팅을 하지않고, 저장된 데이터로만 표시해준다.
		if ( focusModeFlug == 1 )
		{
			console.log("[sys] 포커스모드 활성화 상태, currYear=" + currYear + " calendarjs.getYear()=" + calendarjs.getYear() +
					" currMo0nth=" + currMonth + " calendarjs.getMonth()=" + calendarjs.getMonth() + " calendarjs.getDayOfMonth()=" + calendarjs.getDayOfMonth() );
		}
		
		var pannel = document.getElementById('calendar_view');
		
		pannel.innerHTML = "";
		
		buffer = new StringBuffer();
		
		// 구현 이슈! getDate, flug값이 과연 필요할까? 이벤트 객체에 포함되는 걸로 판명된 이상 웹 표준화는 불필요할 것 같은데.. 
		
		buffer.append(
				"<table id=\"calendar_table\" border=0 "
				+ " onMouseUp=\"eventCall_block_day(event, this,'" + calendarjs.getDate() + "','up');\" "
				+ " onMouseDown=\"eventCall_block_day(event, this,'" + calendarjs.getDate() + "','down');\" "
				+ " onMouseMove=\"eventCall_block_day(event, this,'" + calendarjs.getDate() + "','move');\" "
				+ "><tbody id='calendar_table_body'>"
			);
		
		
		//buffer.append("<table id='calendar_table' border=0><tbody>");
		buffer.append("	<tr id='title'>");
		buffer.append("		<td colspan=7 >");
		buffer.append("			<div id='title_div'>");
		
		// 무엇을 사용할지, 무엇이 적합할지..?
		buffer.append("			<a href='javascript:;' onclick=\"calendar_drow("+yy+", "+(mm - 1)+"); return false; \"' id='b_rpev'>◀　</a>");
		buffer.append(" 		<a href='javascript:;' onclick=\"calendar_drow("+yy+", "+(mm)+"); return false; \"' id='b_date'>"+yy+"년&nbsp;"+ (((mm+1) < 10)? "0" : "") + (mm+1) + "월");
		buffer.append("			<a href='javascript:;' onclick=\"calendar_drow("+yy+", "+(mm + 1)+"); return false; \"' id='b_next'>　▶</a>");
		buffer.append("			&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick=\"calendar_drow(); return false; \"' id='b_reset'>reset</a>");
		
// 		buffer.append("			<a href='javascript:calendar_drow("+yy+", "+(mm - 1)+");' id='b_rpev'>◀　</a>");
// 		buffer.append(" 		<a href='javascript:calendar_drow("+yy+", "+mm+");' id='b_date'>"+yy+"년&nbsp;"+ (((mm+1) < 10)? "0" : "") + (mm+1) + "월");
// 		buffer.append("			<a href='javascript:calendar_drow("+yy+", "+(mm + 1)+");' id='b_next'>　▶</a>");
// 		buffer.append("			&nbsp;&nbsp;&nbsp;<a href='javascript:calendar_drow();' id='b_reset'>reset</a>");
		
		buffer.append("</div>");
		buffer.append("</td>");
		buffer.append("</tr>");
		buffer.append("<tr id='week'>");
		buffer.append("<td id='week_red'>일</td>");
		buffer.append("<td id='week_just'>월</td>");
		buffer.append("<td id='week_just'>화</td>");
		buffer.append("<td id='week_just'>수</td>");
		buffer.append("<td id='week_just'>목</td>");
		buffer.append("<td id='week_just'>금</td>");
		buffer.append("<td id='week_blue'>토</td>");
		buffer.append("</tr>");
		
		//console.log("[sys_03] currYear=" + currYear + " calendarjs.getYear()=" + calendarjs.getYear() + " currMonth=" + currMonth + " calendarjs.getMonth()=" + calendarjs.getMonth() + " calendarjs.getDayOfMonth()=" + calendarjs.getDayOfMonth() );
		
		calendarjs.set(new Date(save.date_min_string));
		var date_max_object = new Date(save.date_max_string);
		//console.log("[sys_EX] " + calendarjs.getDate() + " ~ " + save.date_max + "  달력 한 페이지 성립~ ");
		
		safelimit = 0;
		
		while( calendarjs.get().getTime() <= date_max_object.getTime() )
		//while( currYear >= calendarjs.getYear() && currMonth >= calendarjs.getMonth() )
		{
			++safelimit;
			
			if (++safelimit > 5000)
			{
				alert("safelimit 터짐 : " + "무한루프 빠져나옴");
				break;
			}
			
			buffer.append("<tr id='block_week'>");

			//console.log("[sys] 돌리고 돌리고 : " + " currYear=" + currYear + " calendarjs.getYear()=" + calendarjs.getYear() + " currMonth=" + currMonth + " calendarjs.getMonth()=" + calendarjs.getMonth()+ " calendarjs.getDayOfMonth()=" + calendarjs.getDayOfMonth() );
			
			// calendarjs.getDayOfWeek(); 0 = 일요일 ~ 6 = 토요일
			
			for( var step = 0; step < 7; step++ )
			{
// 				buffer.append(
// 							"<td id=\"block_day\" "
// 							+ " onclick=\"eventCall_block_day(event, this,'" + calendarjs.getDate() + "','click');\" "
// 							+ " onMouseDown=\"eventCall_block_day(event, this,'" + calendarjs.getDate() + "','click');\" "
// 							+ ">"
// 							+ calendarjs.format("dd")
// 						);
				
				buffer.append("<td id=\"block_day\">" + calendarjs.format("dd") );
				
				for (var k = 0; k < save.array_rooms.length; k++)
				{
					s_style_outside = "";
					s_style_inside = "";
					s_text_inside = "";
					
					s_color_bar = " background-color:#" + color_table[k] + ";";
					
					var room = save.array_rooms[k];
					
					// 2014-04-06 캐시 시스템 업데이트! 알고리즘 적용 요망! (일단 동일한 작동은 하니 우선순위 미루어둠..)
					
					// 극히 비효율적인 코드지만.. 시간 관계상ㅠㅠ 차후 알고리즘 개선 요망!
					var dataFocus = calendarjs.getDate();
					var dataFocus_end;
					var arrayLen = save.array_reservations.length;
					
					for ( var c = 0; c < arrayLen; c++ )
					{
						var reser = save.array_reservations[c];
						
						//console.log("테스트 전..");
						
						//var checkDate = new Date(calendarjs.getYear(), calendarjs.getMonth(), calendarjs.getDayOfMonth());
						var checkDate = new Date(calendarjs.getDate());
						var startDate = new Date(reser.startdate);
						var endDate = new Date(reser.startdate);
						endDate.addDate(reser.days - 1);
						
						//console.log("테스트 : " + startDate.toDateString() + " ~ " + endDate.toDateString() + "    VS " + checkDate.toDateString());
						
						if (checkDate.getTime() >= startDate.getTime() && 
								checkDate.getTime() <= endDate.getTime() &&
								reser.roomnumber == room.roomNumber )
						{
							//console.log("테스트!! : " + reser.roomnumber + " vs " + room.roomNumber );
							//console.log("예약번호=" + reser.resernumber + "  예약날짜=" + startDate.getDate() + " 지금일자=" + checkDate.getDate() +  " vs  끝나는날짜=" + endDate.getDate() + "           days=" + reser.days );
							
							//endDate.addDate(-1);
							
							var s_widthSize = 0;
							var s_widthLine = "";
							
							if ( checkDate.getDate() == startDate.getDate() )
							{
								// 처음 그래프
								s_style_outside = s_color_outline + s_border
												+ s_padding;
								s_style_inside = s_color_bar + s_relative_lv4 + s_textoption_left;
								
								if ( reser.days == 1 )
								{
									s_style_outside += s_radius_left + s_radius_right + s_margin_center_ex;
									s_style_inside += s_radius_left + s_radius_right;
								}
								else if ( calendarjs.getDayOfWeek() != 6 )
								{
									s_style_outside += s_radius_left + s_margin_left;
									s_style_inside += s_radius_left;
									
									var s_widthSizeMax = ((7 - calendarjs.getDayOfWeek()) * 100) -5;
								
									s_widthSize = (reser.days * 100);
									
									if ( s_widthSize > s_widthSizeMax )
									{
										s_widthSize = s_widthSizeMax;
									}
									
									s_widthSize -= 25;
									s_widthLine = " width:" + s_widthSize + "%;";
									
									s_style_outside += s_relative_lv2 + s_widthLine;
									//s_style_outside += s_widthLine;
								}
								else
								{
									s_style_outside += s_radius_left + s_margin_left;
									s_style_inside += s_radius_left;
								}
	
								// 그래프 내부에 삽입될 글자
								s_text_inside = reser.memberid + "_" + reser.resernumber;
								
								// 최대 글자수는 14자리까지
								if ( s_text_inside.length > 14 )
								{
									var memberid_cut = reser.memberid.substring(0,(13 - (reser.resernumber+"").length));
									s_text_inside = memberid_cut + "_" + reser.resernumber;
								}
							}
							else if ( checkDate.getDate() == endDate.getDate() )
							{
								// 마지막 그래프
								if ( calendarjs.getDayOfWeek() != 0 )
								{
									s_style_outside = s_color_outline + s_border
													+ s_margin_right + s_radius_right
													+ s_padding + s_relative_lv2;
									
									s_style_inside = s_color_bar + s_radius_right + s_relative_lv4 + s_width_over + s_margin_right_in_exisn;
								}
								else
								{
									s_style_outside = s_color_outline + s_border
													+ s_radius_right
													+ s_padding + s_relative_lv2;
									
									s_style_inside = s_color_bar + s_radius_right + s_relative_lv4;
								}
							}
							else
							{
								// 중간 그래프
								s_style_outside = s_color_outline + s_border
												+ s_margin_center + s_padding;
								
								s_style_inside = s_color_bar;
								
								if ( calendarjs.getDayOfWeek() == 0 )
								{
									var s_widthSizeMax = ((7 - calendarjs.getDayOfWeek()) * 100) - 5;
									
									// 테스트 코드 : (new Date("2014-04-05").getTime() - new Date("2014-04-04").getTime()) / 86400000;
									// 테스트 결과 : 1
									var dayDiff = (checkDate.getTime() - startDate.getTime()) / 86400000.0;
									
									s_widthSize = ((reser.days - dayDiff) * 100);
									
									if ( s_widthSize > s_widthSizeMax )
									{
										s_widthSize = s_widthSizeMax;
									}
									
									s_widthSize -= 25;
									
									//console.log("dayDiff=" + dayDiff + "   s_widthSize=" + s_widthSize);
									
									s_widthLine = " width:" + s_widthSize + "%;";
									
									s_style_outside += s_relative_lv2 + s_widthLine;
									s_style_inside += s_relative_lv3;
								}
								else
								{
									s_style_inside += s_relative_lv2;
								}
							}
						}
					}
					
					buffer.append("<li id='block_day_bar'>");
					buffer.append("<div id='outline"+(s_style_outside!=""?"_on":"")+"' style='"+s_style_outside+"'>");
					buffer.append("<div id='inline"+(s_style_inside!=""?"_on":"")+"' style='"+s_style_inside+"'>&nbsp;" + s_text_inside + "</div>");
					buffer.append("</div>");
					buffer.append("</li>");
				}
				
				calendarjs.addDay(1);
				
				if ( new Date(calendarjs.getDate()).addDate(-1).getMonth() != ( currMonth * 1 ) )
					buffer.append("<div id='block_day_overlap'></div>");
				else
					buffer.append("<div id='block_day_overlap_on'></div>");
				
				buffer.append("</td>");
			}
			
			buffer.append("</tr>");
			
		}
			
		buffer.append("</tbody></table>");
		
		pannel.innerHTML = buffer.toString("");
		
		console.log("[sys] draw a successful calendar. ");
	};
</script>
</head>
<body onselectstart="return false" oncontextmenu="return false">
<!-- <a href='javascript:;' onclick='calendar_drow(2014, 6); return false;' >test button</a> -->


<% if ( adminMod == Calendars.YES && loginuser.getUserType().equals("admin") ) { %>
<!-- 이런식으로 관리자 처리 -->
<% } %>


<div id='calendar_div'>
	<div id='calendar_view'> <h2 id='service_message'> ... DB를 로딩중입니다. 잠시만 기다려주세요 ... </h2> </div>
	
	<div id='calendar_ect'>
	</div>
	
	<div id='calendar_control'>
	
	<% Date now = new Date(); %>
	
		<div id='form_fixed'>
			<form method="get" action="#" class="date">
				<p id='form_head_info'>
					- Information -
				</p>
				<p id='form_head_join'>
					- Reservation -
				</p>
				<p id ='form_head_line'>
				&nbsp
				</p>
			    <p id='form_date1'>
			      <label>Check-in : &nbsp</label>
			      
			      <input type="text" id="input_s_yy" value=" " READONLY>
			      <label>Year &nbsp</label>
			      
			      <input type="text" id="input_s_mm" value=" " READONLY>
			      <label>Month &nbsp</label>
			      
			      <input type="text" id="input_s_dd" value=" " READONLY>
			      <label>Day &nbsp</label>
			    </p>
			    <br />
			    <p id='form_date2'>
			      <label>Check-out : &nbsp</label>
			      
			      <input type="text" id="input_e_yy"value=" " READONLY>
			      <label>Year &nbsp</label>
			      
			      <input type="text" id="input_e_mm" value=" " READONLY>
			      <label>Month &nbsp</label>
			      
			      <input type="text" id="input_e_dd" value=" " READONLY>
			      <label>Day &nbsp</label>
			    </p>
			    <p id='form_slide_days'>
			    </p>
			    <p id='form_button'>
			    </p>
			    <p id='form_info1'>
			      <br />
			      <input type="text" id="input_people" value=" " READONLY>
			      <label>People &nbsp</label>
			      
			      <input type="text" id="input_regdate" value=" " READONLY>
			      <label>Reg Date &nbsp&nbsp&nbsp&nbsp</label>
			      
			      <br />
			      <label>Room Name : &nbsp</label>
			      <input type="text" id="input_room"value=" " READONLY>
			      
			      <label>&nbsp no.</label>
			      <input type="text" id="input_room_number"value=" " READONLY>
			      
			    </p>
			    
			    <div id='form_room_list'>
			    	<select id="input_room_selecter"  name="input_room_selecter">
					      <option value="101" selected="selected">RED</option>
					      <option value="102">BLUE</option>
					      <option value="201">ORANGE</option>
					      <option value="202">WHITE</option>
					</select>
			    </div>

			    <div id='form_option_list'>
			    	<label id ="label_option"> - Option - </label>
				    <input type='checkbox' name="input_option_1" id='input_option_1' value='1'>바비큐(BBQ/그릴)<br /><hr color='#9f9eaa' width='80%'>
				    <input type='checkbox' name="input_option_2" id='input_option_2' value='2'>베이비(아기침대/용품)<br /><hr color='#9f9eaa' width='80%'>
				    <input type='checkbox' name="input_option_3" id='input_option_3' value='3'>프로포즈이벤트<br /><hr color='#9f9eaa' width='80%'>
			    </div>
			    
			    <div id='form_join1'>
			    </div>
			    <div id='form_join2'>
			    </div>
			    <div id='form_join3'>
			      <input type="text" id="input_people" value="test">
			      <label>People &nbsp</label>
			      
			      <br />
			      <label>Room Name : &nbsp</label>
			      <input type="text" id="input_room"value="se ">
			      
			      <label>&nbsp no.</label>
			      <input type="text" id="input_room_number"value="se ">
			  	  
			  	    <br />
		        	<a href="javascript:;" class="b_join" onclick="lowSubmit();">예약하기!</a>
			    </div>
			    
			    <br /><br />
			    
			    <div id='form_info2'>
			      <label id ="label_option"> - Option - </label>
			      <br />
			      <div id='form_options'>
			      </div>
			      <br />
			      <label id='label_pricetotal'>Total Price &nbsp</label>
			      <br />
			      <input type="text" id="input_pricetotal" value=" " READONLY>
			    </div>
			</form>
		</div>
		<div id='form_additional'>
		</div>
	
		
	</div>
</div>
</body>
</html>
